/*
p p+1 2p+1 3p+2 5p+3 8p+5 13p+8 21p+13

a[i]=fibo[i]*p+fibo[i-1]
*/
#include <cstdio>
#include <algorithm>
using namespace std;
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}

inline void write(long long x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
#define DEBUG
using ll=long long;
const int N=50;
ll fibo[N];
ll a, x, b;
ll p;
void init()
{
    fibo[1]=1; 
    for(int i=2; i<N; i++)
        fibo[i]=fibo[i-1]+fibo[i-2];
}

void solve()
{
    read(a), read(x), read(b);
    p=0;
    if(x-fibo[a-1]>0 && (x-fibo[a-1])%fibo[a]==0)
        p=(x-fibo[a-1])/fibo[a];
    
    if(p==0) puts("-1");
    else write(fibo[b]*p+fibo[b-1]), puts("");
}

signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif
    // ios::sync_with_stdio(0);
    // cin.tie(0); cout.tie(0);
    init();
    int T=1; scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}